home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * FileOpen.cpp * * Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com * * This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter * * FlasKMPEG is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * FlasKMPEG is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "FlasKMPEG.h" #include "RunState.h" #include "error.h" #include ".\Input\DVDSelector.h" #include ".\FileOpen.h" extern TConfig o; extern TRunState rs; extern HWND hMainWnd; extern void EnableMenu(); extern void DisableMenu(); extern VBitmap DecodedImage; extern unsigned char MPEGImage[MAX_IMAGE_MEM]; extern HINSTANCE hInst; int OpenFile() { OPENFILENAME oifn; char InputFile[1024]; CStreamDetector *detector; int selected; // Initialize OPENFILENAME ZeroMemory(&oifn, sizeof(OPENFILENAME)); oifn.lStructSize = sizeof(OPENFILENAME); oifn.hwndOwner = hMainWnd; strcpy(InputFile,""); oifn.lpstrFile = InputFile; oifn.nMaxFile = sizeof(InputFile); oifn.lpstrFilter = "MPEG video files\0*.m2v;*.mpg;*.vob;*.m1v;*.m2v;*.mpe;*.mpeg;*.mv2;*.mpv\0All\0*.*\0"; oifn.nFilterIndex = 1; oifn.lpstrFileTitle = "FlasK MPEG - Choose input stream file"; oifn.nMaxFileTitle = 0; oifn.lpstrInitialDir = o.options.inputDir; oifn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(!GetOpenFileName(&oifn)) return 0; //Main_Bitstream_Filename = InputFile; if(rs.audio){ delete rs.audio; rs.audio=NULL; } if(rs.video){ delete rs.video; rs.video=NULL; } if( rs.SD == NULL ){ //Stream Detector structure doesn't exist rs.SD=new TStreamDetector; //Create a new one } else{ delete rs.SD; rs.SD=new TStreamDetector; } //Create a new stream detector detector= new CStreamDetector; //Set input file if(detector) if(!detector->SetFile(InputFile)){ PrintError(UNS_FILE_OPEN,(int)hMainWnd, 0); delete detector; return FALSE; } //Now, recognize stream switch(detector->RecognizeType()) { case 0: // Set the beginning of the compile rs.startFilePos = 0; //Stream was recognized as a valid stream //Detect streams inside file if(!detector->GetStreams(rs.SD, o.options.lurk_size )){ //There was a problem detecting the streams PrintError(UNS_FILE_OPEN,(int)hMainWnd, 0); delete detector; return FALSE; } //After recognizing type, you've obtained stream and substream //available if(rs.SD->n_video_streams){ selected=rs.SD->video_selected; if(rs.SD->video[selected].streamID) rs.video = new VideoWrapper( InputFile, rs.SD->video[selected].streamID, -1, -1, -1, DVD_MODE); } else { PrintError(NO_VIDEO_TRACK,(int)hMainWnd, 0); return FALSE; } if(rs.SD->n_audio_streams){ selected=rs.SD->audio_selected[0]; if(rs.SD->audio[selected].streamID) rs.audio = new Audio( InputFile, rs.SD->audio[selected].streamID, rs.SD->audio[selected].subStreamID, DVD_MODE); } else rs.audio=NULL; #ifdef TESTING_MULTIAUDIO rs.audio2 = new Audio( InputFile, 0xBD, 0x82, DVD_MODE); #endif //No error enable MENU EnableMenu(); switch(rs.video->detectedFrameRateCode){ case 1: // HACK: LSX PLUGIN WANTS SCALE TO BE LIKE 2997/1000 o.options.timeBase.scale=23976; o.options.timeBase.sampleSize=1000; break; case 2: o.options.timeBase.scale=24; o.options.timeBase.sampleSize=1; break; case 3: o.options.timeBase.scale=25; o.options.timeBase.sampleSize=1; break; case 4: o.options.timeBase.scale=2997; o.options.timeBase.sampleSize=100; break; case 5: o.options.timeBase.scale=30; o.options.timeBase.sampleSize=1; break; default: o.options.timeBase.scale=25; o.options.timeBase.sampleSize=1; break; } //o.options.audioMode=DO_AUDIO; if(rs.audio){ /*if(audio->isMPEG && o.options.audioMode==DO_AUDIO) o.options.audioMode=NO_AUDIO;*/ if( !rs.audio->isAC3 && !rs.audio->isMPEG ) o.options.audioMode=NO_AUDIO; } else o.options.audioMode=NO_AUDIO; return 0; break; case INPUT_NOEXIST: MessageBox( hMainWnd, "Input file doesn't exit", "FlasK Warning", MB_OK); break; case IS_TRANSPORTSTREAM: MessageBox( hMainWnd, "This file seems to be a transport stream. Transport Streams are not supported", "FlasK Warning", MB_OK); break; case NOT_RECOGNIZED: MessageBox( hMainWnd, "This file doesn't seem to be a valid supported format. Supported formats are:\nMPEG2 program streams\nMPEG1 program streams\n", "FlasK Warning", MB_OK); break; case NO_AUDIOVIDEO: MessageBox( hMainWnd, "This file doesn't seem to contain audio or video information.\n", "FlasK Warning", MB_OK); break; default: break; } DisableMenu(); return 1; } int PrepareInputFromIFO(CinputStream *input, CIFOParser *ifo, TDVDSelector *sel) { int i,val; TPlaySequenceSpan inpSpan; if(!input || !ifo || !sel) return 0; for(i=0; i<ifo->PGCs[sel->selected_pgc].BuiltPGC[sel->selected_angle].playinfo.GetCount(); i++) { inpSpan.start = ifo->PGCs[sel->selected_pgc].BuiltPGC[sel->selected_angle].playinfo[i].start; inpSpan.end = ifo->PGCs[sel->selected_pgc].BuiltPGC[sel->selected_angle].playinfo[i].end; val=input->AddSpan(&inpSpan); if(!val) return 0; } return input->ValidatePlaySequence(); } int OpenDVDFile() { OPENFILENAME oifn; char InputFile[1024]; // Initialize OPENFILENAME ZeroMemory(&oifn, sizeof(OPENFILENAME)); oifn.lStructSize = sizeof(OPENFILENAME); oifn.hwndOwner = hMainWnd; strcpy(InputFile,""); oifn.lpstrFile = InputFile; oifn.nMaxFile = sizeof(InputFile); oifn.lpstrFilter = "DVD IFO files\0*.ifo\0All\0*.*\0"; oifn.nFilterIndex = 1; oifn.lpstrFileTitle = "FlasK MPEG - Choose input DVD IFO file"; oifn.nMaxFileTitle = 0; oifn.lpstrInitialDir = o.options.inputDir; oifn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(!GetOpenFileName(&oifn)) return IFO_OPENING_NOERROR; if(rs.audio){ delete rs.audio; rs.audio=NULL; } if(rs.video){ delete rs.video; rs.video=NULL; } if(rs.video_inp){ delete rs.video_inp; rs.video_inp = NULL; } if(!(rs.video_inp = new CinputStream)) return 0; if(rs.audio_inp){ delete rs.audio_inp; rs.audio_inp = NULL; } if(!(rs.audio_inp = new CinputStream)) return 0; DisableMenu(); rs.ifo = new CIFOParser; int audio_stream_id,audio_substream_id, subpic_stream_id = -1, subpic_substream_id = -1; int len; TDVDSelector sel_info; if(rs.ifo->Load(InputFile)) { if(OpenDVDSelector(hMainWnd, hInst, rs.ifo, &sel_info)){ // Setting pgc selected into rs rs.DVDSelections = sel_info; // Preparing input file len = strlen(InputFile); InputFile[len-5] = '1'; InputFile[len-4] = '.'; InputFile[len-3] = 'v'; InputFile[len-2] = 'o'; InputFile[len-1] = 'b'; // Try opening the file FILE *file; if( !(file=fopen(InputFile, "rb")) ) return 0; fclose(file); rs.video_inp->OpenStream(InputFile, DVD_MODE); rs.video_inp->SetWorkingMode(PLAYSEQ_MODE); rs.audio_inp->OpenStream(InputFile, DVD_MODE); rs.audio_inp->SetWorkingMode(PLAYSEQ_MODE); // Prepare CinputStream if(!PrepareInputFromIFO(rs.video_inp, rs.ifo, &sel_info) ){ delete rs.ifo; rs.ifo = NULL; return 0; } if(!PrepareInputFromIFO(rs.audio_inp, rs.ifo, &sel_info) ){ delete rs.ifo; rs.ifo = NULL; return 0; } if(sel_info.has_subpic){ subpic_stream_id = 0xBD; subpic_substream_id = 0x20 + sel_info.selected_subpic; } rs.video = new VideoWrapper( InputFile, 0xE0, -1, subpic_stream_id, subpic_substream_id, DVD_MODE); rs.video->UnSetInput(); rs.video->SetInput(rs.video_inp); if(sel_info.has_audio){ audio_stream_id = sel_info.audio_type == DVDSEL_AC3 ? 0xBD : (sel_info.audio_type==DVDSEL_MPEG ? (0xC0+sel_info.selected_audio) : 0 ); audio_substream_id = sel_info.audio_type == DVDSEL_AC3 ? (0x80+sel_info.selected_audio) : 0; rs.audio = new Audio( InputFile, audio_stream_id, audio_substream_id, DVD_MODE); rs.audio->UnSetInput(); rs.audio->SetInput(rs.audio_inp); } } // Set the beginning of the compile rs.startFilePos = 0; switch(rs.video->detectedFrameRateCode){ case 1: // HACK: LSX PLUGIN WANTS SCALE TO BE LIKE 2997/1000 o.options.timeBase.scale=23976; o.options.timeBase.sampleSize=1000; break; case 2: o.options.timeBase.scale=24; o.options.timeBase.sampleSize=1; break; case 3: o.options.timeBase.scale=25; o.options.timeBase.sampleSize=1; break; case 4: o.options.timeBase.scale=2997; o.options.timeBase.sampleSize=100; break; case 5: o.options.timeBase.scale=30; o.options.timeBase.sampleSize=1; break; default: o.options.timeBase.scale=25; o.options.timeBase.sampleSize=1; break; } if(rs.audio){ /*if(audio->isMPEG && o.options.audioMode==DO_AUDIO) o.options.audioMode=NO_AUDIO;*/ if( !rs.audio->isAC3 && !rs.audio->isMPEG ) o.options.audioMode=NO_AUDIO; } else o.options.audioMode=NO_AUDIO; EnableMenu(); return IFO_OPENING_NOERROR; } else{ DisableMenu(); return 0; } }